<template>
	<view class="follow">
		<view class="nav-header-box">
			<view class="header-left" @click="goback">
				<view class="header-left-icon"></view>
			</view>
			<view class="header-title">
				<view class="header-p">{{isFans==1?'我的关注':'我的粉丝'}}</view>
			</view>
			<view class="header-right">
				<view class="header-right-icon"></view>
			</view>
		</view>
		<view v-if="isNull==true" class="ul-author">
			<view class="media-null">{{isFans==1?'您还没有关注任何人':'您暂时还没有粉丝'}}</view>
		</view>
		<view v-else class="ul-author">
			<block v-for="(item,index) in mediaList" :key="'c'+ item.id">
				<view class="li-author" @click="goUserDetail(item.follow_user)">
					<view class="author-left">
						<view class="author-img">
							<image v-if="isFans==1" :src="item.follow_avators" mode="aspectFit"></image>
							<image v-else :src="item.user_avators" mode="aspectFit"></image>
						</view>
						<view class="author-name">{{isFans==1?item.follow_name:item.user_name}}</view>
					</view>
					<view class="author-right" @click="userFollower(item)">
						<!-- <view :class="item.status==1?'author-follow':''">{{item.status==1?'已关注':'关注'}} -->
						<view class="author-follow">{{isFans==1?'已关注':'拉黑'}}</view>
					</view>
				</view>
			</block>
		</view>

	</view>
</template>

<script>
	import {
		getFollow,
		removeFollow,
		getFans
	} from "@/api/request"
	export default {
		data() {
			return {
				user_id: "",
				isFans: "",
				mediaList: [],
				isNull: false
			}
		},
		methods: {
			goUserDetail(id){
				uni.navigateTo({
					url:"/pages/userdetail/userdetail?id=" + id
				})
			},
			userFollower(item) {
					let data = {
						user_id: item.user_id,
						follow_user: item.follow_user
					};
					removeFollow(data).then(content => {
						// console.log(content);
						let {
							code
						} = content;
						if (code == 200) {
							if(this.isFans==1){
								uni.showToast({
									title: "取关成功",
								})
							}else{
								uni.showToast({
									title: "拉黑成功",
								})
							}
							
						}
					}).then(content => {
						this.getUserFollow()
					})

			},
			//返回上一页
			goback() {
				uni.navigateBack({
					delta: 1, //返回层数，2则上上页
				})
			},
			getUserFollow() {
				if (this.isFans == 1) {
					let data = {
						user_id: this.user_id
					}
					getFollow(data).then(content => {
						// console.log("2222===>",content);
						let {
							code,
							data
						} = content
						if (code) {
							if (data.length == 0) {
								// console.log(this.isNull);
								this.isNull = true
							}
							this.mediaList = data

						}
					})
				} else {
					let data = {
						follow_user: this.user_id
					};
					// console.log(data);
					getFans(data).then(content => {
						// console.log(content);
						let {
							code,
							data
						} = content;
						if (code == 200) {
							this.mediaList = data
							console.log(this.mediaList);
							if (data.length == 0) {
								this.isNull = true
							}
						}
					})
				}
			}
		},
		onLoad(e) {
			this.isFans = e.type
			// console.log(e);
		},
		onShow() {
			this.user_id = localStorage.getItem("user_id")
			// console.log(this.user_id);
			this.getUserFollow();
		}
	}
</script>

<style lang="scss" scoped>
	.follow {
		position: relative;
		// background-color: #fff;
		width: 100%;
		padding: 120rpx $uni-box-padding;
	}

	.nav-header-box {
		position: fixed;
		top: 0;
		left: 0;
		padding: 30rpx;
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		background-color: #fff;
		z-index: 1;
		// height: 48rpx;

		.header-title {
			font-size: 32rpx;
			font-weight: bold;

		}

		.header-left,
		.header-right {
			width: 48rpx;
			height: 48rpx;
			background-repeat: no-repeat;
			background-size: 100%;
		}

		.header-left {
			background-image: url("@/static/image/back.png");
		}

		.header-right {
			background-image: url("@/static/image/more2.png");
		}
	}

	.ul-author {
		width: 100%;
		text-align: center;

		.media-null {
			width: 100%;
			text-align: center;
			height: 300rpx;
			line-height: 300rpx;
		}

		.li-author {
			padding-bottom: 40rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

		}

		.author-left {
			display: flex;
			align-items: center;

			.author-img {
				width: 100rpx;
				height: 100rpx;

				image {
					border: 1px solid #f0f0f0;
					border-radius: 50%;
					width: 100%;
					height: 100%;
				}
			}

			.author-name {
				padding-left: 20rpx;
				font-size: 36rpx;
				color: #000;
				font-weight: bold;
			}
		}

		.author-right {
			background-color: #1877F2;
			border-radius: 10rpx;
			font-size: 32rpx;
			color: #fff;
			width: 136rpx;
			height: 66rpx;
			line-height: 66rpx;
			text-align: center;

			.author-follow {
				text-align: center;
				background-color: #fff;
				border: 1px solid #1877F2;
				font-size: 32rpx;
				width: 136rpx;
				color: #1877F2;
				border-radius: 10rpx;
			}
		}
	}
</style>